package com.easy.dev.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easy.dev.bo.ResponseStatus;
import com.easy.dev.dto.TFieldDTO;
import com.easy.dev.entity.TField;
import com.easy.dev.service.impl.BaseServiceImpl;
import com.easy.dev.service.impl.TFieldServiceImpl;
import com.easy.dev.utils.ClassNameUtils;
import com.easy.dev.vo.Result;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Api(tags = "TField操作接口")
@RestController
@RequestMapping("/tField")
public class TFieldController extends BaseController<TField> {

    @Autowired
    private TFieldServiceImpl tFieldService;

    @Override
    BaseServiceImpl getService() {
        return tFieldService;
    }

    @GetMapping("/table/{tableName}")
    public Result getDatasByTableName(@PathVariable("tableName") String tableName) {
        QueryWrapper<TField> wrapper = new QueryWrapper<TField>();
        wrapper.eq("table_name", ClassNameUtils.getUnderlineTableName(tableName));
        List<TField> tFieldList = tFieldService.selectList(wrapper);
        return getResult(ResponseStatus.SELECT_SUCCESS, tFieldList);
    }

    @PostMapping("/list")
    public Result getList(@RequestBody TFieldDTO dto) {
        QueryWrapper<TField> wrapper = new QueryWrapper<TField>();
        wrapper.eq("table_name", ClassNameUtils.getUnderlineTableName(dto.getTableName()));
        List<TField> tFieldList = tFieldService.selectList(wrapper);
        return getResult(ResponseStatus.SELECT_SUCCESS, tFieldList);
    }




}